package com.cheng.student.controller.servlet;

import com.cheng.student.service.StudentServiceImpl;
import com.cheng.student.utils.Util;

import javax.persistence.criteria.CriteriaBuilder;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.regex.Pattern;
//1
@WebServlet(name = "getStudentFullsServlet", value = "/teacher/GetStudentFullsServlet")
public class GetStudentFullsServlet
        extends HttpServlet
{
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException
    {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException
    {

        String area = request.getParameter("area");       //地区
        String gender = request.getParameter("gender");   //性别
        String academy = request.getParameter("academy"); //学院
        String major = request.getParameter("major");     //专业
        String batch = request.getParameter("batch");     //批次
        String type = request.getParameter("type");       //类别

/*        if("".equals(area))
        {
            area = null;
        }
        if("".equals(gender))
        {
            gender = null;
        }
        if("".equals(academy))
        {
            academy = null;
        }
        if("".equals(major))
        {
            major = null;
        }
        if("".equals(batch))
        {
            batch = null;
        }
        if("".equals(type))
        {
            type = null;
        }*/


        String startS = request.getParameter("start");
        String endS = request.getParameter("end");
        int start = 0;
        int end = 0;
        //合理性校验，不合理响应空
        if(startS == null||endS == null||"".equals(startS)||"".equals(endS))
        {
            return;
        }
        try
        {
            start = Integer.parseInt(startS);
            end = Integer.parseInt(endS);
        }
        catch (Exception e)
        {
            return;
        }
        if (start < 0 || end < 0 || end < start)
        {
            return;
        }
        String jsonOfStudentFulls = new StudentServiceImpl().getJsonOfStudentFulls(
                area,gender,academy,major,batch,type,start, end);

        response.getWriter().write(jsonOfStudentFulls);

    }
}
